package com.guoxin.mashibing.executor;

import java.util.concurrent.*;

/**
 * @author guoxin
 * @date 2019/7/12
 */
public class FutureTaskTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task = new FutureTask<>(() -> {
            TimeUnit.MILLISECONDS.sleep(500);
            return 1000;
        });

        new Thread(task).start();

        System.out.println(task.get());

        ExecutorService service = Executors.newFixedThreadPool(5);
        Future<Integer> future = service.submit(() -> {
            TimeUnit.MILLISECONDS.sleep(500);
            return 1;
        });
//        System.out.println(future.get());
        System.out.println(future.isDone());
    }
}
